Skip to content

fix: stop mutating package-level columns variable in member list view#1002

Open
AdeshDeshmukh wants to merge 1 commit into
goharbor:mainfrom
AdeshDeshmukh:fix/member-list-global-columns-mutation
Open

fix: stop mutating package-level columns variable in member list view#1002
AdeshDeshmukh wants to merge 1 commit into
goharbor:mainfrom
AdeshDeshmukh:fix/member-list-global-columns-mutation

Conversation

@AdeshDeshmukh

@AdeshDeshmukh AdeshDeshmukh commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Description

ListMembers in pkg/views/member/list/view.go modifies a package-level var columns slice when rendering in non-wide mode. Since the variable is global, a non-wide call permanently strips columns from it — meaning subsequent calls with --wide will render an incomplete table.

This is a classic shared-mutable-state bug. The fix is straightforward: make a local copy at function entry and operate on that instead. The global now acts as an immutable template.

Changes

  • pkg/views/member/list/view.go — copy columns into a local variable, use it for both mutation and the table model

Testing

  • go build ./pkg/views/member/... — passes
  • go vet ./pkg/views/member/... — passes
  • Manually verified: harbor project member list and --wide both render correctly after the change

Fixes #1038

Copilot AI review requested due to automatic review settings June 15, 2026 20:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates member list rendering to avoid mutating the shared columns slice when switching between wide and non-wide output.

Changes:

  • Introduces localColumns to keep column changes local to ListMembers.
  • Uses localColumns when constructing the table model instead of the global columns.
Comments suppressed due to low confidence (1)

pkg/views/member/list/view.go:1

  • When wide is false, localColumns = utils.RemoveColumns(...) runs once per member even though the result is identical for every iteration. Compute localColumns once before the loop (based on wide) and only build rows inside the loop; this avoids repeated work and makes the control flow clearer.
// Copyright Project Harbor Authors

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/views/member/list/view.go
Comment thread pkg/views/member/list/view.go Outdated
Comment thread pkg/views/member/list/view.go Outdated
The ListMembers function was modifying the global 'columns' variable
when rendering in non-wide mode via utils.RemoveColumns. This meant
that after the first non-wide call, every subsequent call — even with
--wide — would see a truncated set of columns.

Fix by making a local copy of the columns slice at the start of the
function and operating on that instead. The global now serves only as
a read-only template.

Fixes goharbor#3

Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
@AdeshDeshmukh AdeshDeshmukh force-pushed the fix/member-list-global-columns-mutation branch from 01f0703 to 9b6e3cd Compare June 15, 2026 20:09
@qcserestipy qcserestipy added invalid This doesn't seem right no-issue This PR has now issue that has been discussed on the scope of the PR labels Jul 6, 2026
@qcserestipy

Copy link
Copy Markdown
Collaborator

This references the wrong issue, please open a dedicated real issue

@AdeshDeshmukh

Copy link
Copy Markdown
Contributor Author

Hey @qcserestipy — I've opened issue #1038 and updated the PR description to link to it. Also resolved the Copilot threads. Let me know if there's anything else you'd like me to adjust. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right no-issue This PR has now issue that has been discussed on the scope of the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: ListMembers mutates global columns variable breaking subsequent --wide calls

3 participants